//
//  Status.m
//  王雷Sinoweibo
//
//  Created by wanglei on 16/11/15.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "Status.h"
#import "User.h"

@implementation Status

//计算在下载单张图片的时候该下载谁的图片
//被转发的原创微博中如果有图片  转发微博中就一定不会有图片

- (NSArray<NSURL *> *)pictureURLs{
    
    if (self.retweeted_status != nil) {
        return self.retweeted_status.imageURLs;
    }
    return self.imageURLs;
}


- (void)setPic_urls:(NSArray *)pic_urls{
    if (!pic_urls) {
  return;
    }
    NSMutableArray *mutarray = [[NSMutableArray alloc]init];
    for (NSDictionary *item in pic_urls) {
        NSLog(@"item = %@",item);
        NSString *str = item[@"thumbnail_pic"];
//   将字符串str中的字段thumbnail换成bmiddle,目的是为了显示大图,根据对比网页版的微博图片url发现的
  //     NSString *strNew = [str stringByReplacingOccurrencesOfString:@"thumbnail" withString:@"bmiddle"];
        NSURL *urls = [NSURL URLWithString:str];
        [mutarray addObject:urls];
    }
    self.imageURLs = mutarray;
}

- (Status *)initWithStatusDict:(NSDictionary *)dict;{
    if(self = [super init]){
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

+ (instancetype)StatuesWithDict:(NSDictionary *)dict;{
    return [[self alloc]initWithStatusDict:dict];
}

//对于模型中嵌套模型的赋值应该采用这种方法进行,记得提前return
- (void)setValue:(id)value forKey:(NSString *)key{
    if ([key isEqualToString:@"user"]) {
        NSDictionary *dictuser = value;
        self.user = [User UserWithDict:dictuser];
        return;
    }
    
    if ([key isEqualToString:@"retweeted_status"]) {
        
        NSDictionary *dictuser = value;
        
        self.retweeted_status = [Status StatuesWithDict:dictuser];
        
        return;
    }
    
    [super setValue:value forKey:key];
}
-(void)setValue:(id)value forUndefinedKey:(NSString *)key{}

@end
